package com.lolc.ihm.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JRadioButton;

import com.lolc.LoLAutoCounterManager;
import com.lolc.ihm.MainWindow;
import com.lolc.ihm.component.MyTeamPlayerBox;


public class SetMyTurnListener implements ActionListener {
	
	private int id;
	
	public SetMyTurnListener(int id) {
		super();
		this.id=id;
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		// TODO Auto-generated method stub
		if(arg0.getSource() instanceof JRadioButton)
		{
			JRadioButton rb = (JRadioButton) arg0.getSource();
			if(rb.isSelected())
			{	
				LoLAutoCounterManager.getInstance().setMyTeamChampionAtPosition(id, null);
				
				for(MyTeamPlayerBox playerBox : MainWindow.getInstance().getMyTeamBox().getMyTeamPlayerBoxes())
				{
					if(playerBox.getId()==this.id)
					{						
						//Refresh box
						playerBox.resetBox();
						playerBox.initMyTurnComponent(playerBox.getId());
						playerBox.validate();	
						
						LoLAutoCounterManager.getInstance().setMyTeamLaneAtPosition(id, null);
					}
					else
					{
						playerBox.resetBox();
						playerBox.initComponents(playerBox.getId());
						playerBox.validate();						
					}				
				}					
			}
			else
			{
				//
				for(MyTeamPlayerBox playerBox : MainWindow.getInstance().getMyTeamBox().getMyTeamPlayerBoxes())
				{
					if(playerBox.getId()==this.id)
					{
						playerBox.resetBox();
						playerBox.initComponents(playerBox.getId());
						playerBox.validate();
						break;
					}
					/*else
					{
						playerBox.resetBox();
						playerBox.initComponents(playerBox.getId());
						playerBox.validate();						
					}*/					
				}
			}
			MainWindow.getInstance().getMyTeamBox().validate();			
		}
	}
}
